from playwright.sync_api import Playwright, sync_playwright, expect
import re
import time


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context(ignore_https_errors=True, record_har_mode="full", record_har_path="D:\\webrunner\\webrunner-x86_64-windows-20250616145951-16898d5b9\\filestorage\\recorder\\simulate\\测盟会会议\\har_1751702095.har", service_workers="block")
    time.sleep(1)
    page = context.new_page()
    time.sleep(1)
    page.goto("http://localhost:8080/")
    time.sleep(1)
    page.goto("http://localhost:8080/news")
    time.sleep(1)
    page.goto("http://localhost:8080/login")
    time.sleep(1)
    page.get_by_placeholder("用户名").click()
    time.sleep(1)
    page.get_by_placeholder("用户名").fill("admin")
    time.sleep(1)
    page.get_by_placeholder("密码").click()
    time.sleep(1)
    page.get_by_placeholder("密码").fill("123456")
    time.sleep(1)
    page.get_by_role("button", name="登录").click()
    time.sleep(1)
    page.get_by_role("menuitem", name="会议管理").click()
    time.sleep(1)
    page.get_by_role("button", name="创建会议").click()
    time.sleep(1)
    page.get_by_role("textbox", name="* 会议名称").click()
    time.sleep(1)
    page.get_by_role("textbox", name="* 会议名称").fill("test")
    time.sleep(1)
    page.get_by_placeholder("请输入图片名称或选择图片").click()
    time.sleep(1)
    page.get_by_role("button", name="选择图片").click()
    time.sleep(1)
    page.get_by_role("button", name="选择图片").set_input_files("tv.jpg")
    time.sleep(1)
    page.get_by_role("combobox", name="* 开始时间").click()
    time.sleep(1)
    page.get_by_role("row", name="27 28 29 30 31 1 2").get_by_text("29").click()
    time.sleep(1)
    page.get_by_role("combobox", name="* 开始时间").click()
    time.sleep(1)
    page.get_by_role("dialog", name="创建会议").locator("div").filter(has_text=re.compile(r"^开始时间$")).locator("div").first.click()
    time.sleep(1)
    page.get_by_label("结束时间").click()
    time.sleep(1)
    page.get_by_role("row", name="3 4 5 6 7 8 9").get_by_text("8").click()
    time.sleep(1)
    page.get_by_role("button", name="确定").click()
    time.sleep(1)
    page.locator("#w-e-element-0").click()
    time.sleep(1)
    page.get_by_role("button", name="保存").click()
    time.sleep(1)
    page.get_by_role("textbox", name="会议名称").click()
    time.sleep(1)
    page.get_by_role("textbox", name="会议名称").fill("test")
    time.sleep(1)
    page.get_by_role("textbox", name="会议名称").press("Enter")
    time.sleep(1)
    page.get_by_role("button", name="查询").click()
    time.sleep(1)
    page.get_by_role("button", name="查询").click()
    time.sleep(1)
    page.get_by_role("row", name="test 管理员 未开始 已审核 2025-07-29 00:00 test 修改 详情 删除").get_by_role("button", name="修改").click()
    time.sleep(1)
    page.get_by_role("textbox", name="* 会议名称").click()
    time.sleep(1)
    page.get_by_role("textbox", name="* 会议名称").fill("test1")
    time.sleep(1)
    page.locator("#w-e-element-5").click()
    time.sleep(1)
    page.locator("#w-e-element-5").click()
    time.sleep(1)
    page.get_by_role("button", name="保存").click()
    time.sleep(1)
    page.get_by_role("row", name="test1 管理员 未开始 已审核 2025-07-29 00:00 test1 修改 详情 删除").get_by_role("button", name="删除").click()
    time.sleep(1)
    page.get_by_role("dialog", name="确认删除").get_by_role("button", name="删除").click()
    page.close()

    # ---------------------
    time.sleep(2)
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
